package com.fieldchain.ex.fa100.ui.money.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.fieldchain.ex.fa100.R;
import com.fieldchain.ex.fa100.access.Constant;
import com.fieldchain.ex.fa100.base.MyBaseActivity;
import com.fieldchain.ex.fa100.ui.money.adapter.MarketChoseAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.fieldchain.ex.fa100.utils.net.access.HttpRequest;
import com.fieldchain.ex.fa100.utils.net.modle.StringListRequest;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/10/25
 */
public class MarketChoseActivity extends MyBaseActivity implements View.OnClickListener {
    private RelativeLayout reaBack;
    private TextView tvCenter;
    private RecyclerView rv;
    private RelativeLayout reaEmpty;
    private TextView tvEmpty;



    private MarketChoseAdapter adapter;
    private String coin;
    private List<String>mList=new ArrayList<>();
    @Override
    public void findView() {
        reaBack = findViewById(R.id.rea_back);
        tvCenter = findViewById(R.id.tv_center);
        rv = findViewById(R.id.rv);
        reaEmpty = findViewById(R.id.rea_empty);
        tvEmpty = findViewById(R.id.tv_empty);
    }

    @Override
    public void setValue() {
        coin=getIntent().getStringExtra("coin");
        adapter=new MarketChoseAdapter(mContext);
        rv.setLayoutManager(new LinearLayoutManager(mContext));
        rv.setAdapter(adapter);
        tvCenter.setText(coin.toUpperCase());
        reaBack.setOnClickListener(this);
        rv.setAdapter(adapter);


        tvEmpty.setText("暂未开放对应交易市场");
        getData();
    }

    @Override
    public int getLayout() {
        return R.layout.activity_marketchose;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.rea_back:
                finish();
                break;
        }
    }

    public void getData(){
        HashMap map=new HashMap();
        map.put("suf",coin.toLowerCase());

        HttpRequest.getInstance().getRequest(map, Constant.marketChose,new StringListRequest() {
            @Override
            public void onSucess(List<String> list, int code, String msg) {
                if(code==200){
                    mList.clear();
                    mList.addAll(list);
                    adapter.setData(mList);
                }
                if(mList.size()==0){
                    reaEmpty.setVisibility(View.VISIBLE);
                }else {
                    reaEmpty.setVisibility(View.GONE);
                }
            }

            @Override
            public void onFaild(Exception e) {
                reaEmpty.setVisibility(View.GONE);
            }
        });
    }
}
